<?php
// No direct access
defined('_JEXEC') or die;

jimport('joomla.application.component.controller');

class PromotionsController extends JControllerLegacy
{

	public function display($cachable = false, $urlparams = false)
	{
		$cachable	= true;	// Huh? Why not just put that in the constructor?
		$user		= JFactory::getUser();

		$id		= JRequest::getInt('w_id');
		$vName	= JRequest::getCmd('view', 'promotions');
		JRequest::setVar('view', $vName);
		
		$lName	 = JRequest::getCmd('layout', 'default');
		switch ($lName){
			case "details":
				$pormID = JRequest::getCmd('id');
				$model = $this->getModel($vName);
				$model->addPoint($user->id, $pormID);
			break;
		}
		

		if ($user->get('id') ||($_SERVER['REQUEST_METHOD'] == 'POST' && $vName = 'categories')) {
			$cachable = false;
		}
        
		$safeurlparams = array(
			'id'				=> 'INT',
			'limit'				=> 'INT',
			'limitstart'		=> 'INT',
			'filter_order'		=> 'CMD',
			'filter_order_Dir'	=> 'CMD',
			'lang'				=> 'CMD'
		);
		return parent::display($cachable,$safeurlparams);
	}

	function encryptcart(){
		$cart = JRequest::getVar('params');
		$config = new JConfig;
		$serect = $config->secret;
		
		
		$cart = base64_encode(md5($serect).base64_encode($cart));
		
		$result = array();
		$result['success'] = true;
		$result['data'] = $cart;
		$result = json_encode($result);
		echo "({$result})";
		exit();
	}
	
	function decryptcart(){
		$cart = JRequest::getVar('params');
		$config = new JConfig;
		$serect = md5($config->secret);
		$cart = base64_decode($cart);
		$cart = str_replace($serect, '', $cart);
		$cart = base64_decode($cart);
		
		$result['success'] = true;
		$result['data'] = $cart;
		$result = json_encode($result);
		echo "({$result})";
		exit();
	}

}
